package com.example.canteen.converter;

import com.example.canteen.dao.Dish;
import com.example.canteen.dto.DishDTO;

public class DishConverter {
    public static DishDTO convertDish(Dish dish) {
        DishDTO dishDTO = new DishDTO();
        dishDTO.setId(dish.getId());
        dishDTO.setName(dish.getName());
        if (dish.getCategory() != null) {
            dishDTO.setCategoryDTO(CategoryConverter.convertCategory(dish.getCategory()));
        }
        dishDTO.setComponents(dish.getComponents());
        dishDTO.setCategoryName(dish.getCategory().getName());
        return dishDTO;
    }

    public static Dish convertDish(DishDTO dishDTO) {
        Dish dish = new Dish();
        dish.setId(dishDTO.getId());
        dish.setName(dishDTO.getName());
        if (dishDTO.getCategoryDTO() != null) {
            dish.setCategory(CategoryConverter.convertCategory(dishDTO.getCategoryDTO()));
        }
        dish.setComponents(dishDTO.getComponents());
        return dish;
    }
}
